package com.hoodbrains.insideloc.maps;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.util.Log;
import android.graphics.Canvas;
import android.graphics.Point;

public class Magasin extends DrawableObject {

	private Map<String, Point> rayons;
	private Set<Gondole> gondoles;

	public Set<Gondole> getGondoles() {
		return gondoles;
	}

	protected Map<String, Point> getRayons() {
		return this.rayons;
	}

	public void draw(Canvas canvas) {
		this.rayons = new HashMap<String, Point>();
		super.draw(canvas);
		if (this.gondoles != null) {
			for (Gondole gondole : this.gondoles) {
				gondole.draw(canvas, this.rayons);
			}
		}
	}
	
	public void addGondole (Gondole toAdd)
	{
		gondoles.add(toAdd);
	}
	public void removeGondole (Gondole toRemove)
	{
		gondoles.remove(toRemove);
	}
	public static Magasin deserialize(Element elem) {
		Magasin magasin = new Magasin();
		magasin.gondoles = new HashSet<Gondole>();
		NodeList gondoleElems = elem.getElementsByTagName("gondole");
		Log.e("Magasin", "n°" + gondoleElems.getLength());
		for (int i = 0; i < gondoleElems.getLength(); i++) {
			Log.e("Magasin", "n°" + i);
			magasin.gondoles.add(Gondole.deserialize((Element) gondoleElems
					.item(i)));

		}
		return magasin;
	}

	public Element serialize(Document doc) {
		Element elem = doc.createElement("magasin");
		for (Gondole gondole : gondoles) {
			elem.appendChild(gondole.serialize(doc));
		}

		return elem;
	}
}
